package com.cms.service;


import java.util.List;

import org.apache.log4j.Logger;

import com.cms.model.ChannelTerraceInfo;
import com.service.AbstractDateService;
import com.utils.dbcp.ConnectionManager;
import com.utils.dbcp.ModelGenerator;

/**
 * @author luoyh
 * @date 2014‎-‎3‎-27
 */
public class ChannelTerraceInfoImpl extends AbstractDateService implements ChannelTerraceInfoService {

	private Logger logger;
	public ChannelTerraceInfoImpl() {
		logger = Logger.getLogger(this.getClass());
	}

	@Override
	public ChannelTerraceInfo getChannelTerraceInfo(int id) {
		String sql = "select * from t_channelterrace where id=" + String.valueOf(id) + "";
		ModelGenerator<ChannelTerraceInfo> dbcpmg = new ModelGenerator<ChannelTerraceInfo>(ChannelTerraceInfo.class);
		return dbcpmg.generate(base, sql);
	}

	@Override
	public List<ChannelTerraceInfo> getChannelTerraceInfos() {
		String sql = "select * from t_channelterrace order by id desc";
		logger.debug("sql: " + sql);
		ModelGenerator<ChannelTerraceInfo> dbcpmg = new ModelGenerator<ChannelTerraceInfo>(ChannelTerraceInfo.class);
		return dbcpmg.generateList(base, sql);
	}

	@Override
	public boolean insertChannelTerraceInfo(ChannelTerraceInfo model) {
		model.setId(getTableId("t_channelterrace"));
		String sql = 
			"insert into t_channelterrace(id,channelId,terraceId,relevanceid,contractdivide,dividetype,channelName,channelpass,remark) " +
			"values(" + String.valueOf(model.getId()) + ","+String .valueOf(model.getChannelId()) +",'" +String.valueOf(model.getTerraceId())+ "','"  +
			String.valueOf(model.getRelevanceid()) + "','"+ String.valueOf(model.getContractdivide()) + "','" + model.getDividetype() + "','" + 
			model.getChannelName()+ "','"+model.getChannelpass()+"','"+model.getGlremark()+"')";
		return ConnectionManager.getInstance().execute(base, sql);
	}

	@Override
	public boolean updateChannelTerraceInfo(ChannelTerraceInfo model) {
		String sql = 
				"update t_channelterrace set channelId='" + String.valueOf(model.getChannelId()) + "',"+
						"terraceId='" + String.valueOf(model.getTerraceId()) + "'," +
						"relevanceid='" + String.valueOf(model.getRelevanceid()) + "'," +
						"contractdivide='" + String.valueOf(model.getContractdivide()) + "'," +
						"dividetype='" + model.getDividetype() + "'," + 
						"channelName='" + model.getChannelName() + "'," +
						"channelpass='" + model.getChannelpass() + "'," +
						"remark='" + model.getGlremark()+"' " +
						" where id=" + String.valueOf(model.getId()) + "";
		System.out.println(sql);
			return ConnectionManager.getInstance().execute(base, sql);
	}

	@Override
	public boolean deleteChannelTerraceInfo(ChannelTerraceInfo model) {
		String sql = "delete from t_channelterrace where id=" + String.valueOf(model.getId()) + "";
		return ConnectionManager.getInstance().execute(base, sql);
	}

	@Override
	public List<ChannelTerraceInfo> getChannelTerraceInfos(int channelId) {
		String sql = "select * from t_channelterrace where channelId=" + String.valueOf(channelId) + "";
		ModelGenerator<ChannelTerraceInfo> dbcpmg = new ModelGenerator<ChannelTerraceInfo>(ChannelTerraceInfo.class);
		// TODO Auto-generated method stub
		return dbcpmg.generateList(base, sql);
	}

	@Override
	public ChannelTerraceInfo getgetChannelTerraceInfoByRelevanceid(
			String relevanceid) {
		String sql = "select * from t_channelterrace where relevanceid='" + String.valueOf(relevanceid) + "'";
		ModelGenerator<ChannelTerraceInfo> dbcpmg = new ModelGenerator<ChannelTerraceInfo>(ChannelTerraceInfo.class);
		return dbcpmg.generate(base, sql);
	}
	
	/*public boolean getByTerraceId(ChannelTerraceInfo model,int terraceId){		
		model.setId(getTableId("t_channelterrace"));
		String sql = 
			"insert into t_channelterrace(id,channelId,terraceId,relevanceid,contractdivide,dividetype,channelName,channelpass,remark) " +
			String.valueOf(model.getRelevanceid()) + "','"+ String.valueOf(model.getContractdivide()) + "','" + model.getDividetype() + "','" + 
			model.getChannelName()+ "','"+model.getChannelpass()+"','"+model.getGlremark()+"')";
		return ConnectionManager.getInstance().execute(base, sql);
	}*/

}
